package com.epart.widget.module.board;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.epart.widget.domain.BoardConfig;
import com.epart.widget.support.AbstractWcmsWidgetDao;
import com.epart.widget.util.DBUtil;

/**
 * 게시판Dao
 * 
 * @author cwsong
 * @version 2011. 3. 11.
 */
public class BoardDao extends AbstractWcmsWidgetDao{
	
	/**
	 * 커넥션 을 인자로 박는 생성자
	 * 
	 * @param connection
	 */
	public BoardDao(Connection connection){
		this.connection = connection; 
	}
	
	/**
	 * 게시판 설정 목록을 반환한다.
	 * 
	 * @return 게시판 설정목록
	 */
	public List<BoardConfig> getBoardConfigList() {
		
		StringBuilder sb = new StringBuilder(1000);
		sb.append(" SELECT ");
		sb.append(" * ");
		sb.append(" FROM ");
		sb.append(" cms_boardConfig ");
		sb.append(" ORDER BY ");
		sb.append(" boardConfigNo ASC ");

		PreparedStatement psmt = null;
		ResultSet rs = null;
		ArrayList<BoardConfig> list = null;
		BoardConfig boardConfig = null;

		try {
			psmt = connection.prepareStatement(sb.toString());
			rs = psmt.executeQuery();

			list = new ArrayList<BoardConfig>();
			while (rs.next()) {
				boardConfig = new BoardConfig();
				boardConfig.setBoardConfigNo(rs.getInt("boardConfigNo"));
				boardConfig.setBoardConfigTitle(rs.getString("boardConfigTitle"));
				boardConfig.setBoardRegdate(rs.getDate("boardRegdate"));
				// TODO: 관리자 목록
				list.add(boardConfig);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			DBUtil.doFinally(rs, psmt, connection);
		}

		return list;
	}

}
